#include "stdafx.h"
#include "wf_actionhandler.h"

#include "pf_commands.h"

#include "wf_blocksadd.h"
#include "wf_blocksattributes.h"
#include "wf_blockscreate.h"
#include "wf_blocksedit.h"
#include "wf_blocksexplode.h"
#include "wf_blocksfreezeall.h"
#include "wf_blocksinsert.h"
#include "wf_blocksremove.h"
#include "wf_blockstoggleview.h"
#include "wf_dimaligned.h"
#include "wf_dimangular.h"
#include "wf_dimdiametric.h"
#include "wf_dimleader.h"
#include "wf_dimlinear.h"
#include "wf_dimradial.h"
#include "wf_drawarc.h"
#include "wf_drawarc3p.h"
#include "wf_drawarctangential.h"
#include "wf_drawcircle.h"
#include "wf_drawcircle2p.h"
#include "wf_drawcircle3p.h"
#include "wf_drawcirclecr.h"
#include "wf_drawellipseaxis.h"
#include "wf_drawhatch.h"
#include "wf_drawimage.h"
#include "wf_drawline.h"
#include "wf_drawlineangle.h"
#include "wf_drawlinebisector.h"
#include "wf_drawlinefree.h"
#include "wf_drawlinehorvert.h"
#include "wf_drawlineparallel.h"
#include "wf_drawlineparallelthrough.h"
#include "wf_drawlinepolygon.h"
#include "wf_drawlinepolygon2.h"
#include "wf_drawlinerectangle.h"
#include "wf_drawlinerelangle.h"
#include "wf_drawlinetangent1.h"
#include "wf_drawlinetangent2.h"
#include "wf_drawpoint.h"
#include "wf_drawspline.h"
#include "wf_drawtext.h"
#include "wf_editcopy.h"
#include "wf_editpaste.h"
#include "wf_editundo.h"
#include "wf_fileopen.h"
#include "wf_filenew.h"
#include "wf_filesave.h"
#include "wf_filesaveas.h"
#include "wf_infoangle.h"
#include "wf_infoarea.h"
#include "wf_infodist.h"
#include "wf_infodist2.h"
#include "wf_infoinside.h"
#include "wf_infototallength.h"
#include "wf_layersadd.h"
#include "wf_layersedit.h"
#include "wf_layersfreezeall.h"
#include "wf_layersremove.h"
#include "wf_layerstogglelock.h"
#include "wf_layerstoggleview.h"
#include "wf_libraryinsert.h"
#include "wf_lockrelativezero.h"
#include "wf_modifyattributes.h"
#include "wf_modifybevel.h"
#include "wf_modifycut.h"
#include "wf_modifydelete.h"
#include "wf_modifydeletefree.h"
#include "wf_modifydeletequick.h"
#include "wf_modifyentity.h"
#include "wf_modifyexplodetext.h"
#include "wf_modifymirror.h"
#include "wf_modifymove.h"
#include "wf_modifymoverotate.h"
#include "wf_modifyrotate.h"
#include "wf_modifyrotate2.h"
#include "wf_modifyround.h"
#include "wf_modifyscale.h"
#include "wf_modifystretch.h"
#include "wf_modifytrim.h"
#include "wf_modifytrimamount.h"
#include "wf_optionsdrawing.h"
#include "wf_select.h"
#include "wf_selectall.h"
#include "wf_selectcontour.h"
#include "wf_selectintersected.h"
#include "wf_selectinvert.h"
#include "wf_selectlayer.h"
#include "wf_selectsingle.h"
#include "wf_selectwindow.h"
#include "wf_setrelativezero.h"
#include "wf_setsnapmode.h"
#include "wf_setsnaprestriction.h"
#include "wf_snapintersectionmanual.h"
#include "wf_toolregeneratedimensions.h"
#include "wf_zoomauto.h"
#include "wf_zoomin.h"
#include "wf_zoompan.h"
#include "wf_zoomprevious.h"
#include "wf_zoomredraw.h"
#include "wf_zoomwindow.h"

#include "wf_drawpolyline.h"
#include "wf_polylineadd.h"
#include "wf_polylineappend.h"
#include "wf_polylinedel.h"
#include "wf_polylinedelbetween.h"
#include "wf_polylinetrim.h"


#include "pf_selection.h"

#include "wf_mainwindowinterface.h"
#include "ui_cadtoolbarsnap.h"

/**
 * Constructor
 */
WF_ActionHandler::WF_ActionHandler(WF_MainWindowInterface* mw) {
    PF_DEBUG->print("QG_ActionHandler::QG_ActionHandler");
    mainWindow = mw;

    snapFree = NULL;
    snapGrid = NULL;
    snapEndpoint = NULL;
    snapOnEntity = NULL;
    snapCenter = NULL;
    snapMiddle = NULL;
    snapDist = NULL;
    snapIntersection = NULL;

    restrictNothing = NULL;
    restrictOrthogonal = NULL;
    restrictHorizontal = NULL;
    restrictVertical = NULL;

    lockRelativeZero = NULL;
    PF_DEBUG->print("QG_ActionHandler::QG_ActionHandler: OK");
}



/**
 * Destructor
 */
WF_ActionHandler::~WF_ActionHandler() {
    PF_DEBUG->print("QG_ActionHandler::~QG_ActionHandler");
    PF_DEBUG->print("QG_ActionHandler::~QG_ActionHandler: OK");
}



/**
 * Kills all running selection actions. Called when a selection action
  * is launched to reduce confusion.
   */
void WF_ActionHandler::killSelectActions() {
    PF_GraphicView* gv = mainWindow->getGraphicView();

    if (gv!=NULL) {
        gv->killSelectActions();
    }
}



/**
 * @return Current action or NULL.
 */
PF_ActionInterface* WF_ActionHandler::getCurrentAction() {
    PF_GraphicView* gv = mainWindow->getGraphicView();

    if (gv!=NULL) {
        return gv->getCurrentAction();
    } else {
        return NULL;
    }
}



/**
 * Sets current action.
 *
 * @return Pointer to the created action or NULL.
 */
PF_ActionInterface* WF_ActionHandler::setCurrentAction(LX_Define::ActionType id) {
    PF_DEBUG->print("QG_ActionHandler::setCurrentAction()");
	PF_GraphicView* gv = mainWindow->getGraphicView();
    PF_Document* doc = mainWindow->getDocument();
    PF_ActionInterface* a = NULL;

    // only global options are allowed without a document:
    if (gv==NULL || doc==NULL) {
        PF_DEBUG->print(PF_Debug::D_WARNING,
        	"QG_ActionHandler::setCurrentAction: graphic view or "
        	"document is NULL");
        return NULL;
    }

    switch (id) {
	case LX_Define::ActionFileNew:
		a = new WF_FileNew(*doc, *gv);
		break;
	case LX_Define::ActionFileSave:
		a = new WF_FileSave(*doc, *gv);
		break;
/*
	case LX_Define::ActionFileClose:
		a = new WF_FileClose(*doc, *gv);
		break;
	case LX_Define::ActionFileQuit:
		a = new WF_FileQuit(*doc, *gv);
		break;*/
    case LX_Define::ActionFileOpen:
        a = new WF_FileOpen(*doc, *gv);
        break;
    case LX_Define::ActionFileSaveAs:
        a = new WF_FileSaveAs(*doc, *gv);
        break;

        // Editing actions:
        //
    case LX_Define::ActionEditKillAllActions:
        if (gv!=NULL) {
            // DO we need to call some form of a 'clean' function?
            gv->killAllActions();
            PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarMain);

            PF_Selection s((PF_Container&)*doc, gv);
            s.selectAll(false);
            PF_DIALOGFACTORY->updateSelectionWidget(doc->countSelected());
        }
        break;
    case LX_Define::ActionEditUndo:
        a = new WF_EditUndo(true, *doc, *gv);
        break;
    case LX_Define::ActionEditRedo:
        a = new WF_EditUndo(false, *doc, *gv);
        break;
    case LX_Define::ActionEditCut:
        a = new WF_Select(*doc, *gv, LX_Define::ActionEditCutNoSelect);
        break;
    case LX_Define::ActionEditCutNoSelect:
        a = new WF_EditCopy(false, *doc, *gv);
        break;
    case LX_Define::ActionEditCopy:
        a = new WF_Select(*doc, *gv, LX_Define::ActionEditCopyNoSelect);
        break;
    case LX_Define::ActionEditCopyNoSelect:
        a = new WF_EditCopy(true, *doc, *gv);
        break;
    case LX_Define::ActionEditPaste:
        a = new WF_EditPaste(*doc, *gv);
        break;

        // Selecting actions:
        //
    case LX_Define::ActionSelectSingle:
        gv->killSelectActions();
        a = new WF_SelectSingle(*doc, *gv);
        break;
    case LX_Define::ActionSelectContour:
        gv->killSelectActions();
        a = new WF_SelectContour(*doc, *gv);
        break;
    case LX_Define::ActionSelectAll:
        a = new WF_SelectAll(*doc, *gv, true);
        break;
    case LX_Define::ActionDeselectAll:
        a = new WF_SelectAll(*doc, *gv, false);
        break;
    case LX_Define::ActionSelectWindow:
        gv->killSelectActions();
        a = new WF_SelectWindow(*doc, *gv, true);
        break;
    case LX_Define::ActionDeselectWindow:
        gv->killSelectActions();
        a = new WF_SelectWindow(*doc, *gv, false);
        break;
    case LX_Define::ActionSelectInvert:
        a = new WF_SelectInvert(*doc, *gv);
        break;
    case LX_Define::ActionSelectIntersected:
        gv->killSelectActions();
        a = new WF_SelectIntersected(*doc, *gv, true);
        break;
    case LX_Define::ActionDeselectIntersected:
        gv->killSelectActions();
        a = new WF_SelectIntersected(*doc, *gv, false);
        break;
    case LX_Define::ActionSelectLayer:
        gv->killSelectActions();
        a = new WF_SelectLayer(*doc, *gv);
        break;
		
        // Tool actions:
        //
    case LX_Define::ActionToolRegenerateDimensions:
        a = new WF_ToolRegenerateDimensions(*doc, *gv);
        break;

        // Zooming actions:
        //
    case LX_Define::ActionZoomIn:
        a = new WF_ZoomIn(*doc, *gv, LX_Define::In, LX_Define::Both);
        break;
    case LX_Define::ActionZoomOut:
        a = new WF_ZoomIn(*doc, *gv, LX_Define::Out, LX_Define::Both);
        break;
    case LX_Define::ActionZoomAuto:
        a = new WF_ZoomAuto(*doc, *gv);
        break;
    case LX_Define::ActionZoomWindow:
        a = new WF_ZoomWindow(*doc, *gv);
        break;
    case LX_Define::ActionZoomPan:
        a = new WF_ZoomPan(*doc, *gv);
        break;
    case LX_Define::ActionZoomPrevious:
        a = new WF_ZoomPrevious(*doc, *gv);
        break;
    case LX_Define::ActionZoomRedraw:
        a = new WF_ZoomRedraw(*doc, *gv);
        break;

        // Drawing actions:
        //
    case LX_Define::ActionDrawPoint:
        a = new WF_DrawPoint(*doc, *gv);
        break;
    case LX_Define::ActionDrawLine:
        a = new WF_DrawLine(*doc, *gv);
        break;
    case LX_Define::ActionDrawLineAngle:
        a = new WF_DrawLineAngle(*doc, *gv, 0.0, false);
        break;
    case LX_Define::ActionDrawLineHorizontal:
        a = new WF_DrawLineAngle(*doc, *gv, 0.0, true);
        break;
    case LX_Define::ActionDrawLineHorVert:
        a = new WF_DrawLineHorVert(*doc, *gv);
        break;
    case LX_Define::ActionDrawLineVertical:
        a = new WF_DrawLineAngle(*doc, *gv, M_PI/2.0, true);
        break;
    case LX_Define::ActionDrawLineFree:
        a = new WF_DrawLineFree(*doc, *gv);
        break;
    case LX_Define::ActionDrawLineParallel:
        a = new WF_DrawLineParallel(*doc, *gv);
        break;
    case LX_Define::ActionDrawLineParallelThrough:
        a = new WF_DrawLineParallelThrough(*doc, *gv);
        break;
    case LX_Define::ActionDrawLineRectangle:
        a = new WF_DrawLineRectangle(*doc, *gv);
        break;
    case LX_Define::ActionDrawLineBisector:
        a = new WF_DrawLineBisector(*doc, *gv);
        break;
    case LX_Define::ActionDrawLineTangent1:
        a = new WF_DrawLineTangent1(*doc, *gv);
        break;
    case LX_Define::ActionDrawLineTangent2:
        a = new WF_DrawLineTangent2(*doc, *gv);
        break;
    case LX_Define::ActionDrawLineOrthogonal:
        a = new WF_DrawLineRelAngle(*doc, *gv, M_PI/2.0, true);
        break;
    case LX_Define::ActionDrawLineRelAngle:
        a = new WF_DrawLineRelAngle(*doc, *gv, M_PI/2.0, false);
        break;
    case LX_Define::ActionDrawPolyline:
        a = new WF_DrawPolyline(*doc, *gv);
        break;
    case LX_Define::ActionPolylineAdd:
        a = new WF_PolylineAdd(*doc, *gv);
        break;
    case LX_Define::ActionPolylineAppend:
        a = new WF_PolylineAppend(*doc, *gv);
        break;
    case LX_Define::ActionPolylineDel:
        a = new WF_PolylineDel(*doc, *gv);
        break;
    case LX_Define::ActionPolylineDelBetween:
        a = new WF_PolylineDelBetween(*doc, *gv);
        break;
    case LX_Define::ActionPolylineTrim:
        a = new WF_PolylineTrim(*doc, *gv);
        break;
    case LX_Define::ActionDrawLinePolygon:
        a = new WF_DrawLinePolygon(*doc, *gv);
        break;
    case LX_Define::ActionDrawLinePolygon2:
        a = new WF_DrawLinePolygon2(*doc, *gv);
        break;
    case LX_Define::ActionDrawCircle:
        a = new WF_DrawCircle(*doc, *gv);
        break;
    case LX_Define::ActionDrawCircleCR:
        a = new WF_DrawCircleCR(*doc, *gv);
        break;
    case LX_Define::ActionDrawCircle2P:
        a = new WF_DrawCircle2P(*doc, *gv);
        break;
    case LX_Define::ActionDrawCircle3P:
        a = new WF_DrawCircle3P(*doc, *gv);
        break;
    case LX_Define::ActionDrawCircleParallel:
        a = new WF_DrawLineParallel(*doc, *gv);
        break;
    case LX_Define::ActionDrawArc:
        a = new WF_DrawArc(*doc, *gv);
        break;
    case LX_Define::ActionDrawArc3P:
        a = new WF_DrawArc3P(*doc, *gv);
        break;
    case LX_Define::ActionDrawArcParallel:
        a = new WF_DrawLineParallel(*doc, *gv);
        break;
    case LX_Define::ActionDrawArcTangential:
        a = new WF_DrawArcTangential(*doc, *gv);
        break;
    case LX_Define::ActionDrawEllipseAxis:
        a = new WF_DrawEllipseAxis(*doc, *gv, false);
        break;
    case LX_Define::ActionDrawEllipseArcAxis:
        a = new WF_DrawEllipseAxis(*doc, *gv, true);
        break;
    case LX_Define::ActionDrawSpline:
        a = new WF_DrawSpline(*doc, *gv);
        break;
    case LX_Define::ActionDrawText:
        a = new WF_DrawText(*doc, *gv);
        break;
    case LX_Define::ActionDrawHatch:
        a = new WF_Select(*doc, *gv, LX_Define::ActionDrawHatchNoSelect);
        break;
    case LX_Define::ActionDrawHatchNoSelect:
        a = new WF_DrawHatch(*doc, *gv);
        break;
    case LX_Define::ActionDrawImage:
        a = new WF_DrawImage(*doc, *gv);
        break;

        // Dimensioning actions:
        //
    case LX_Define::ActionDimAligned:
        a = new WF_DimAligned(*doc, *gv);
        break;
    case LX_Define::ActionDimLinear:
        a = new WF_DimLinear(*doc, *gv);
        break;
    case LX_Define::ActionDimLinearHor:
        a = new WF_DimLinear(*doc, *gv, 0.0, true);
        break;
    case LX_Define::ActionDimLinearVer:
        a = new WF_DimLinear(*doc, *gv, M_PI/2.0, true);
        break;
    case LX_Define::ActionDimRadial:
        a = new WF_DimRadial(*doc, *gv);
        break;
    case LX_Define::ActionDimDiametric:
        a = new WF_DimDiametric(*doc, *gv);
        break;
    case LX_Define::ActionDimAngular:
        a = new WF_DimAngular(*doc, *gv);
        break;
    case LX_Define::ActionDimLeader:
        a = new WF_DimLeader(*doc, *gv);
        break;

        // Modifying actions:
        //
    case LX_Define::ActionModifyAttributes:
        a = new WF_Select(*doc, *gv, LX_Define::ActionModifyAttributesNoSelect);
        break;
    case LX_Define::ActionModifyAttributesNoSelect:
        a = new WF_ModifyAttributes(*doc, *gv);
        break;
    case LX_Define::ActionModifyDelete:
        a = new WF_Select(*doc, *gv, LX_Define::ActionModifyDeleteNoSelect);
        break;
    case LX_Define::ActionModifyDeleteNoSelect:
        a = new WF_ModifyDelete(*doc, *gv);
        break;
    case LX_Define::ActionModifyDeleteQuick:
        a = new WF_Select(*doc, *gv, LX_Define::ActionModifyDeleteQuick);
        break;
    case LX_Define::ActionModifyDeleteFree:
        a = new WF_ModifyDeleteFree(*doc, *gv);
        break;
    case LX_Define::ActionModifyMove:
        a = new WF_Select(*doc, *gv, LX_Define::ActionModifyMoveNoSelect);
        break;
    case LX_Define::ActionModifyMoveNoSelect:
        a = new WF_ModifyMove(*doc, *gv);
        break;
    case LX_Define::ActionModifyRotate:
        a = new WF_Select(*doc, *gv, LX_Define::ActionModifyRotateNoSelect);
        break;
    case LX_Define::ActionModifyRotateNoSelect:
        a = new WF_ModifyRotate(*doc, *gv);
        break;
    case LX_Define::ActionModifyScale:
        a = new WF_Select(*doc, *gv, LX_Define::ActionModifyScaleNoSelect);
        break;
    case LX_Define::ActionModifyScaleNoSelect:
        a = new WF_ModifyScale(*doc, *gv);
        break;
    case LX_Define::ActionModifyMirror:
        a = new WF_Select(*doc, *gv, LX_Define::ActionModifyMirrorNoSelect);
        break;
    case LX_Define::ActionModifyMirrorNoSelect:
        a = new WF_ModifyMirror(*doc, *gv);
        break;
    case LX_Define::ActionModifyMoveRotate:
        a = new WF_Select(*doc, *gv, LX_Define::ActionModifyMoveRotateNoSelect);
        break;
    case LX_Define::ActionModifyMoveRotateNoSelect:
        a = new WF_ModifyMoveRotate(*doc, *gv);
        break;
    case LX_Define::ActionModifyRotate2:
        a = new WF_Select(*doc, *gv, LX_Define::ActionModifyRotate2NoSelect);
        break;
    case LX_Define::ActionModifyRotate2NoSelect:
        a = new WF_ModifyRotate2(*doc, *gv);
        break;
    case LX_Define::ActionModifyEntity:
        a = new WF_ModifyEntity(*doc, *gv);
        break;
    case LX_Define::ActionModifyTrim:
        a = new WF_ModifyTrim(*doc, *gv, false);
        break;
    case LX_Define::ActionModifyTrim2:
        a = new WF_ModifyTrim(*doc, *gv, true);
        break;
    case LX_Define::ActionModifyTrimAmount:
        a = new WF_ModifyTrimAmount(*doc, *gv);
        break;
    case LX_Define::ActionModifyCut:
        a = new WF_ModifyCut(*doc, *gv);
        break;
    case LX_Define::ActionModifyStretch:
        a = new WF_ModifyStretch(*doc, *gv);
        break;
    case LX_Define::ActionModifyBevel:
        a = new WF_ModifyBevel(*doc, *gv);
        break;
    case LX_Define::ActionModifyRound:
        a = new WF_ModifyRound(*doc, *gv);
        break;
    case LX_Define::ActionModifyExplodeText:
        a = new WF_Select(*doc, *gv, LX_Define::ActionModifyExplodeTextNoSelect);
        break;
    case LX_Define::ActionModifyExplodeTextNoSelect:
        a = new WF_ModifyExplodeText(*doc, *gv);
        break;

        // Snapping actions:
        //
    case LX_Define::ActionSnapFree:
        a = new WF_SetSnapMode(*doc, *gv, LX_Define::SnapFree);
        break;
    case LX_Define::ActionSnapGrid:
        a = new WF_SetSnapMode(*doc, *gv, LX_Define::SnapGrid);
        break;
    case LX_Define::ActionSnapEndpoint:
        a = new WF_SetSnapMode(*doc, *gv, LX_Define::SnapEndpoint);
        break;
    case LX_Define::ActionSnapOnEntity:
        a = new WF_SetSnapMode(*doc, *gv, LX_Define::SnapOnEntity);
        break;
    case LX_Define::ActionSnapCenter:
        a = new WF_SetSnapMode(*doc, *gv, LX_Define::SnapCenter);
        break;
    case LX_Define::ActionSnapMiddle:
        a = new WF_SetSnapMode(*doc, *gv, LX_Define::SnapMiddle);
        break;
    case LX_Define::ActionSnapDist:
        a = new WF_SetSnapMode(*doc, *gv, LX_Define::SnapDist);
        break;
    case LX_Define::ActionSnapIntersection:
        a = new WF_SetSnapMode(*doc, *gv, LX_Define::SnapIntersection);
        break;
    case LX_Define::ActionSnapIntersectionManual:
        a = new WF_SnapIntersectionManual(*doc, *gv);
        break;

        // Snap restriction actions:
        //
    case LX_Define::ActionRestrictNothing:
        a = new WF_SetSnapRestriction(*doc, *gv, LX_Define::RestrictNothing);
        break;
    case LX_Define::ActionRestrictOrthogonal:
        a = new WF_SetSnapRestriction(*doc, *gv,
                                            LX_Define::RestrictOrthogonal);
        break;
    case LX_Define::ActionRestrictHorizontal:
        a = new WF_SetSnapRestriction(*doc, *gv,
                                            LX_Define::RestrictHorizontal);
        break;
    case LX_Define::ActionRestrictVertical:
        a = new WF_SetSnapRestriction(*doc, *gv,
                                            LX_Define::RestrictVertical);
        break;

        // Relative zero:
        //
    case LX_Define::ActionSetRelativeZero:
        a = new WF_SetRelativeZero(*doc, *gv);
        break;
    case LX_Define::ActionLockRelativeZero:
        a = new WF_LockRelativeZero(*doc, *gv, true);
        break;
    case LX_Define::ActionUnlockRelativeZero:
        a = new WF_LockRelativeZero(*doc, *gv, false);
        break;

        // Info actions:
        //
    case LX_Define::ActionInfoInside:
        a = new WF_InfoInside(*doc, *gv);
        break;
    case LX_Define::ActionInfoDist:
        a = new WF_InfoDist(*doc, *gv);
        break;
    case LX_Define::ActionInfoDist2:
        a = new WF_InfoDist2(*doc, *gv);
        break;
    case LX_Define::ActionInfoAngle:
        a = new WF_InfoAngle(*doc, *gv);
        break;
    case LX_Define::ActionInfoTotalLength:
        a = new WF_Select(*doc, *gv, LX_Define::ActionInfoTotalLengthNoSelect);
        break;
    case LX_Define::ActionInfoTotalLengthNoSelect:
        a = new WF_InfoTotalLength(*doc, *gv);
        break;
    case LX_Define::ActionInfoArea:
        a = new WF_InfoArea(*doc, *gv);
        break;

        // Layer actions:
        //
    case LX_Define::ActionLayersDefreezeAll:
        a = new WF_LayersFreezeAll(false, *doc, *gv);
        break;
    case LX_Define::ActionLayersFreezeAll:
        a = new WF_LayersFreezeAll(true, *doc, *gv);
        break;
    case LX_Define::ActionLayersAdd:
        a = new WF_LayersAdd(*doc, *gv);
        break;
    case LX_Define::ActionLayersRemove:
        a = new WF_LayersRemove(*doc, *gv);
        break;
    case LX_Define::ActionLayersEdit:
        a = new WF_LayersEdit(*doc, *gv);
        break;
    case LX_Define::ActionLayersToggleView:
        a = new WF_LayersToggleView(*doc, *gv);
        break;
    case LX_Define::ActionLayersToggleLock:
        a = new WF_LayersToggleLock(*doc, *gv);
        break;

        // Block actions:
        //
    case LX_Define::ActionBlocksDefreezeAll:
        a = new WF_BlocksFreezeAll(false, *doc, *gv);
        break;
    case LX_Define::ActionBlocksFreezeAll:
        a = new WF_BlocksFreezeAll(true, *doc, *gv);
        break;
    case LX_Define::ActionBlocksAdd:
        a = new WF_BlocksAdd(*doc, *gv);
        break;
    case LX_Define::ActionBlocksRemove:
        a = new WF_BlocksRemove(*doc, *gv);
        break;
    case LX_Define::ActionBlocksAttributes:
        a = new WF_BlocksAttributes(*doc, *gv);
        break;
    case LX_Define::ActionBlocksEdit:
        a = new WF_BlocksEdit(*doc, *gv);
        break;
    case LX_Define::ActionBlocksInsert:
        a = new WF_BlocksInsert(*doc, *gv);
        break;
    case LX_Define::ActionBlocksToggleView:
        a = new WF_BlocksToggleView(*doc, *gv);
        break;
    case LX_Define::ActionBlocksCreate:
        a = new WF_Select(*doc, *gv, LX_Define::ActionBlocksCreateNoSelect);
        break;
    case LX_Define::ActionBlocksCreateNoSelect:
        a = new WF_BlocksCreate(*doc, *gv);
        break;
    case LX_Define::ActionBlocksExplode:
        a = new WF_Select(*doc, *gv, LX_Define::ActionBlocksExplodeNoSelect);
        break;
    case LX_Define::ActionBlocksExplodeNoSelect:
        a = new WF_BlocksExplode(*doc, *gv);
        break;
		

        // library browser:
        //
    case LX_Define::ActionLibraryInsert:
        a = new WF_LibraryInsert(*doc, *gv);
        break;

        // options:
        //
        //case LX_Define::ActionOptionsGeneral:
        //    a = new PF_ActionOptionsGeneral(*doc, *gv);
        //	break;

    case LX_Define::ActionOptionsDrawing:
        a = new WF_OptionsDrawing(*doc, *gv);
        break;

	
    default:
        PF_DEBUG->print(PF_Debug::D_WARNING,
                        "QG_ActionHandler::setCurrentAction():"
                        "No such action found.");
        break;
    }

    if (a!=NULL) {
        gv->setCurrentAction(a);
    }
	
    PF_DEBUG->print("QG_ActionHandler::setCurrentAction(): OK");
    return a;
}



/**
 * @return Available commands of the application or the current action.
 */
PF_StringList WF_ActionHandler::getAvailableCommands() {
    PF_ActionInterface* currentAction = getCurrentAction();

    if (currentAction!=NULL) {
        return currentAction->getAvailableCommands();
    } else {
        PF_StringList cmd;
        cmd += "line";
        cmd += "rectangle";
        return cmd;
    }
}



/**
 * Launches the command represented by the given keycode if possible.
 *
 * @return true: the command was recognized. 
 *         false: the command is not known and was probably intended for a
 *            running action.
 */
bool WF_ActionHandler::keycode(const QString& code) {
    QString c = code.lower();

    // pass keycode on to running action:
    //PF_keycodeEvent e(cmd);

    //PF_GraphicView* gv = mainWindow->getGraphicView();
    //if (gv!=NULL) {
    //    gv->keycodeEvent(&e);
    //}

    // if the current action can't deal with the keycode,
    //   it might be intended to launch a new keycode
    //if (!e.isAccepted()) {
    // keycode for new action:
    LX_Define::ActionType type = PF_COMMANDS->keycodeToAction(code);
    if (type!=LX_Define::ActionNone) {
        // some actions require special handling (GUI update):
        switch (type) {
        case LX_Define::ActionSnapFree:
            slotSnapFree();
            break;
        case LX_Define::ActionSnapGrid:
            slotSnapGrid();
            break;
        case LX_Define::ActionSnapEndpoint:
            slotSnapEndpoint();
            break;
        case LX_Define::ActionSnapOnEntity:
            slotSnapOnEntity();
            break;
        case LX_Define::ActionSnapCenter:
            slotSnapCenter();
            break;
        case LX_Define::ActionSnapMiddle:
            slotSnapMiddle();
            break;
        case LX_Define::ActionSnapDist:
            slotSnapDist();
            break;
        case LX_Define::ActionSnapIntersection:
            slotSnapIntersection();
            break;
        case LX_Define::ActionSnapIntersectionManual:
            slotSnapIntersectionManual();
            break;

        case LX_Define::ActionRestrictNothing:
            slotRestrictNothing();
            break;
        case LX_Define::ActionRestrictOrthogonal:
            slotRestrictOrthogonal();
            break;
        case LX_Define::ActionRestrictHorizontal:
            slotRestrictHorizontal();
            break;
        case LX_Define::ActionRestrictVertical:
            slotRestrictVertical();
            break;

        default:
            setCurrentAction(type);
            break;
        }
        return true;
    }
    //}

    return false;
}



/**
 * Launches the given command if possible.
 *
 * @return true: the command was recognized. 
 *         false: the command is not known and was probably intended for a
 *            running action.
 */
bool WF_ActionHandler::command(const QString& cmd) {
	PF_DEBUG->print("QG_ActionHandler::command: %s", cmd.latin1());
    QString c = cmd.lower();

    if (c=="\n") {
        PF_GraphicView* gv = mainWindow->getGraphicView();
        if (gv!=NULL) {
            gv->back();
        }
		PF_DEBUG->print("QG_ActionHandler::command: back");
        return true;
    }

    // pass command on to running action:
    PF_CommandEvent e(cmd);

    PF_GraphicView* gv = mainWindow->getGraphicView();
    if (gv!=NULL) {
		PF_DEBUG->print("QG_ActionHandler::command: trigger command event in "
		" graphic view");
        gv->commandEvent(&e);
    }

    // if the current action can't deal with the command,
    //   it might be intended to launch a new command
    if (!e.isAccepted()) {
		PF_DEBUG->print("QG_ActionHandler::command: convert cmd to action type");
        // command for new action:
        LX_Define::ActionType type = PF_COMMANDS->cmdToAction(cmd);
        if (type!=LX_Define::ActionNone) {
			PF_DEBUG->print("QG_ActionHandler::command: setting current action");
            setCurrentAction(type);
			PF_DEBUG->print("QG_ActionHandler::command: current action set");
            return true;
        }
    }

	PF_DEBUG->print("QG_ActionHandler::command: current action not set");
    return false;
}




//void QG_ActionHandler::slotFileNew() {
//	setCurrentAction(LX_Define::ActionFileNew);
//}

void WF_ActionHandler::slotFileOpen() {
    setCurrentAction(LX_Define::ActionFileOpen);
}
/*
void QG_ActionHandler::slotFileSave() {
	setCurrentAction(LX_Define::ActionFileSave);
}
*/

void WF_ActionHandler::slotFileSaveAs() {
    setCurrentAction(LX_Define::ActionFileSaveAs);
}

/*
void QG_ActionHandler::slotFileClose() {
	setCurrentAction(LX_Define::ActionFileClose);
}
 
void QG_ActionHandler::slotFilePrint() {
	setCurrentAction(LX_Define::ActionFilePrint);
}
*/

void WF_ActionHandler::slotZoomIn() {
    setCurrentAction(LX_Define::ActionZoomIn);
}

void WF_ActionHandler::slotZoomOut() {
    setCurrentAction(LX_Define::ActionZoomOut);
}

void WF_ActionHandler::slotZoomAuto() {
    setCurrentAction(LX_Define::ActionZoomAuto);
}

void WF_ActionHandler::slotZoomWindow() {
    setCurrentAction(LX_Define::ActionZoomWindow);
}

void WF_ActionHandler::slotZoomPan() {
    setCurrentAction(LX_Define::ActionZoomPan);
}

void WF_ActionHandler::slotZoomPrevious() {
    setCurrentAction(LX_Define::ActionZoomPrevious);
}

void WF_ActionHandler::slotZoomRedraw() {
    setCurrentAction(LX_Define::ActionZoomRedraw);
}

void WF_ActionHandler::slotToolRegenerateDimensions() {
    setCurrentAction(LX_Define::ActionToolRegenerateDimensions);
}

void WF_ActionHandler::slotEditKillAllActions() {
    setCurrentAction(LX_Define::ActionEditKillAllActions);
}
void WF_ActionHandler::slotEditUndo() {
    setCurrentAction(LX_Define::ActionEditUndo);
}

void WF_ActionHandler::slotEditRedo() {
    setCurrentAction(LX_Define::ActionEditRedo);
}

void WF_ActionHandler::slotEditCut() {
    setCurrentAction(LX_Define::ActionEditCut);
}

void WF_ActionHandler::slotEditCopy() {
    setCurrentAction(LX_Define::ActionEditCopy);
}

void WF_ActionHandler::slotEditPaste() {
    setCurrentAction(LX_Define::ActionEditPaste);
}

void WF_ActionHandler::slotSelectSingle() {
    setCurrentAction(LX_Define::ActionSelectSingle);
}

void WF_ActionHandler::slotSelectContour() {
    setCurrentAction(LX_Define::ActionSelectContour);
}

void WF_ActionHandler::slotSelectWindow() {
    setCurrentAction(LX_Define::ActionSelectWindow);
}

void WF_ActionHandler::slotDeselectWindow() {
    setCurrentAction(LX_Define::ActionDeselectWindow);
}

void WF_ActionHandler::slotSelectAll() {
    setCurrentAction(LX_Define::ActionSelectAll);
}

void WF_ActionHandler::slotDeselectAll() {
    setCurrentAction(LX_Define::ActionDeselectAll);
}

void WF_ActionHandler::slotSelectInvert() {
    setCurrentAction(LX_Define::ActionSelectInvert);
}

void WF_ActionHandler::slotSelectIntersected() {
    setCurrentAction(LX_Define::ActionSelectIntersected);
}

void WF_ActionHandler::slotDeselectIntersected() {
    setCurrentAction(LX_Define::ActionDeselectIntersected);
}

void WF_ActionHandler::slotSelectLayer() {
    setCurrentAction(LX_Define::ActionSelectLayer);
}

void WF_ActionHandler::slotDrawPoint() {
    setCurrentAction(LX_Define::ActionDrawPoint);
}

void WF_ActionHandler::slotDrawLine() {
    setCurrentAction(LX_Define::ActionDrawLine);
}

void WF_ActionHandler::slotDrawLineAngle() {
    setCurrentAction(LX_Define::ActionDrawLineAngle);
}

void WF_ActionHandler::slotDrawLineHorizontal() {
    setCurrentAction(LX_Define::ActionDrawLineHorizontal);
}

void WF_ActionHandler::slotDrawLineHorVert() {
    setCurrentAction(LX_Define::ActionDrawLineHorVert);
}

void WF_ActionHandler::slotDrawLineVertical() {
    setCurrentAction(LX_Define::ActionDrawLineVertical);
}

void WF_ActionHandler::slotDrawLineFree() {
    setCurrentAction(LX_Define::ActionDrawLineFree);
}

void WF_ActionHandler::slotDrawLineParallel() {
    setCurrentAction(LX_Define::ActionDrawLineParallel);
}

void WF_ActionHandler::slotDrawLineParallelThrough() {
    setCurrentAction(LX_Define::ActionDrawLineParallelThrough);
}

void WF_ActionHandler::slotDrawLineRectangle() {
    setCurrentAction(LX_Define::ActionDrawLineRectangle);
}

void WF_ActionHandler::slotDrawLineBisector() {
    setCurrentAction(LX_Define::ActionDrawLineBisector);
}

void WF_ActionHandler::slotDrawLineTangent1() {
    setCurrentAction(LX_Define::ActionDrawLineTangent1);
}

void WF_ActionHandler::slotDrawLineTangent2() {
    setCurrentAction(LX_Define::ActionDrawLineTangent2);
}

void WF_ActionHandler::slotDrawLineOrthogonal() {
    setCurrentAction(LX_Define::ActionDrawLineOrthogonal);
}

void WF_ActionHandler::slotDrawLineRelAngle() {
    setCurrentAction(LX_Define::ActionDrawLineRelAngle);
}

void WF_ActionHandler::slotDrawPolyline() {
    setCurrentAction(LX_Define::ActionDrawPolyline);
}

void WF_ActionHandler::slotPolylineAdd() {
    setCurrentAction(LX_Define::ActionPolylineAdd);
}

void WF_ActionHandler::slotPolylineAppend() {
    setCurrentAction(LX_Define::ActionPolylineAppend);
}

void WF_ActionHandler::slotPolylineDel() {
    setCurrentAction(LX_Define::ActionPolylineDel);
}

void WF_ActionHandler::slotPolylineDelBetween() {
    setCurrentAction(LX_Define::ActionPolylineDelBetween);
}

void WF_ActionHandler::slotPolylineTrim() {
    setCurrentAction(LX_Define::ActionPolylineTrim);
}

void WF_ActionHandler::slotDrawLinePolygon() {
    setCurrentAction(LX_Define::ActionDrawLinePolygon);
}

void WF_ActionHandler::slotDrawLinePolygon2() {
    setCurrentAction(LX_Define::ActionDrawLinePolygon2);
}

void WF_ActionHandler::slotDrawCircle() {
    setCurrentAction(LX_Define::ActionDrawCircle);
}

void WF_ActionHandler::slotDrawCircleCR() {
    setCurrentAction(LX_Define::ActionDrawCircleCR);
}

void WF_ActionHandler::slotDrawCircle2P() {
    setCurrentAction(LX_Define::ActionDrawCircle2P);
}

void WF_ActionHandler::slotDrawCircle3P() {
    setCurrentAction(LX_Define::ActionDrawCircle3P);
}

void WF_ActionHandler::slotDrawCircleParallel() {
    setCurrentAction(LX_Define::ActionDrawCircleParallel);
}

void WF_ActionHandler::slotDrawArc() {
    setCurrentAction(LX_Define::ActionDrawArc);
}

void WF_ActionHandler::slotDrawArc3P() {
    setCurrentAction(LX_Define::ActionDrawArc3P);
}

void WF_ActionHandler::slotDrawArcParallel() {
    setCurrentAction(LX_Define::ActionDrawArcParallel);
}

void WF_ActionHandler::slotDrawArcTangential() {
    setCurrentAction(LX_Define::ActionDrawArcTangential);
}

void WF_ActionHandler::slotDrawEllipseAxis() {
    setCurrentAction(LX_Define::ActionDrawEllipseAxis);
}

void WF_ActionHandler::slotDrawEllipseArcAxis() {
    setCurrentAction(LX_Define::ActionDrawEllipseArcAxis);
}

void WF_ActionHandler::slotDrawSpline() {
    setCurrentAction(LX_Define::ActionDrawSpline);
}

void WF_ActionHandler::slotDrawText() {
    setCurrentAction(LX_Define::ActionDrawText);
}

void WF_ActionHandler::slotDrawHatch() {
    setCurrentAction(LX_Define::ActionDrawHatch);
}

void WF_ActionHandler::slotDrawImage() {
    setCurrentAction(LX_Define::ActionDrawImage);
}

void WF_ActionHandler::slotDimAligned() {
    setCurrentAction(LX_Define::ActionDimAligned);
}

void WF_ActionHandler::slotDimLinear() {
    setCurrentAction(LX_Define::ActionDimLinear);
}

void WF_ActionHandler::slotDimLinearHor() {
    setCurrentAction(LX_Define::ActionDimLinearHor);
}

void WF_ActionHandler::slotDimLinearVer() {
    setCurrentAction(LX_Define::ActionDimLinearVer);
}

void WF_ActionHandler::slotDimRadial() {
    setCurrentAction(LX_Define::ActionDimRadial);
}

void WF_ActionHandler::slotDimDiametric() {
    setCurrentAction(LX_Define::ActionDimDiametric);
}

void WF_ActionHandler::slotDimAngular() {
    setCurrentAction(LX_Define::ActionDimAngular);
}

void WF_ActionHandler::slotDimLeader() {
    setCurrentAction(LX_Define::ActionDimLeader);
}


void WF_ActionHandler::slotModifyAttributes() {
    setCurrentAction(LX_Define::ActionModifyAttributes);
}

void WF_ActionHandler::slotModifyDelete() {
    setCurrentAction(LX_Define::ActionModifyDelete);
}

void WF_ActionHandler::slotModifyDeleteQuick() {
    //setCurrentAction(LX_Define::ActionModifyDeleteQuick);
    setCurrentAction(LX_Define::ActionModifyDeleteNoSelect);
}

void WF_ActionHandler::slotModifyDeleteFree() {
    setCurrentAction(LX_Define::ActionModifyDeleteFree);
}

void WF_ActionHandler::slotModifyMove() {
    setCurrentAction(LX_Define::ActionModifyMove);
}

void WF_ActionHandler::slotModifyRotate() {
    setCurrentAction(LX_Define::ActionModifyRotate);
}

void WF_ActionHandler::slotModifyScale() {
    setCurrentAction(LX_Define::ActionModifyScale);
}

void WF_ActionHandler::slotModifyStretch() {
    setCurrentAction(LX_Define::ActionModifyStretch);
}

void WF_ActionHandler::slotModifyBevel() {
    setCurrentAction(LX_Define::ActionModifyBevel);
}

void WF_ActionHandler::slotModifyRound() {
    setCurrentAction(LX_Define::ActionModifyRound);
}

void WF_ActionHandler::slotModifyMirror() {
    setCurrentAction(LX_Define::ActionModifyMirror);
}

void WF_ActionHandler::slotModifyMoveRotate() {
    setCurrentAction(LX_Define::ActionModifyMoveRotate);
}

void WF_ActionHandler::slotModifyRotate2() {
    setCurrentAction(LX_Define::ActionModifyRotate2);
}

void WF_ActionHandler::slotModifyEntity() {
    setCurrentAction(LX_Define::ActionModifyEntity);
}

void WF_ActionHandler::slotModifyTrim() {
    setCurrentAction(LX_Define::ActionModifyTrim);
}

void WF_ActionHandler::slotModifyTrim2() {
    setCurrentAction(LX_Define::ActionModifyTrim2);
}

void WF_ActionHandler::slotModifyTrimAmount() {
    setCurrentAction(LX_Define::ActionModifyTrimAmount);
}

void WF_ActionHandler::slotModifyCut() {
    setCurrentAction(LX_Define::ActionModifyCut);
}

void WF_ActionHandler::slotModifyExplodeText() {
    setCurrentAction(LX_Define::ActionModifyExplodeText);
}


void WF_ActionHandler::slotSnapFree() {
    disableSnaps();
    if (snapFree!=NULL) {
        snapFree->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(LX_Define::SnapFree);
    }
    setCurrentAction(LX_Define::ActionSnapFree);
}

void WF_ActionHandler::slotSnapGrid() {
    disableSnaps();
    if (snapGrid!=NULL) {
        snapGrid->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(LX_Define::SnapGrid);
    }
    setCurrentAction(LX_Define::ActionSnapGrid);
}

void WF_ActionHandler::slotSnapEndpoint() {
    disableSnaps();
    if (snapEndpoint!=NULL) {
        snapEndpoint->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(LX_Define::SnapEndpoint);
    }
    setCurrentAction(LX_Define::ActionSnapEndpoint);
}

void WF_ActionHandler::slotSnapOnEntity() {
    disableSnaps();
    if (snapOnEntity!=NULL) {
        snapOnEntity->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(LX_Define::SnapOnEntity);
    }
    setCurrentAction(LX_Define::ActionSnapOnEntity);
}

void WF_ActionHandler::slotSnapCenter() {
    disableSnaps();
    if (snapCenter!=NULL) {
        snapCenter->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(LX_Define::SnapCenter);
    }
    setCurrentAction(LX_Define::ActionSnapCenter);
}

void WF_ActionHandler::slotSnapMiddle() {
    disableSnaps();
    if (snapMiddle!=NULL) {
        snapMiddle->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(LX_Define::SnapMiddle);
    }
    setCurrentAction(LX_Define::ActionSnapMiddle);
}

void WF_ActionHandler::slotSnapDist() {
    disableSnaps();
    if (snapDist!=NULL) {
        snapDist->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(LX_Define::SnapDist);
    }
    setCurrentAction(LX_Define::ActionSnapDist);
}

void WF_ActionHandler::slotSnapIntersection() {
    disableSnaps();
    if (snapIntersection!=NULL) {
        snapIntersection->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(LX_Define::SnapIntersection);
    }
    setCurrentAction(LX_Define::ActionSnapIntersection);
}

void WF_ActionHandler::slotSnapIntersectionManual() {
    //disableSnaps();
    /*if (snapIntersectionManual!=NULL) {
        snapIntersectionManual->setChecked(true);
}*/
    /*if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapMode(LX_Define::SnapIntersectionManual);
}*/
    setCurrentAction(LX_Define::ActionSnapIntersectionManual);
}

void WF_ActionHandler::disableSnaps() {
    if (snapFree!=NULL) {
        snapFree->setChecked(false);
    }
    if (snapGrid!=NULL) {
        snapGrid->setChecked(false);
    }
    if (snapEndpoint!=NULL) {
        snapEndpoint->setChecked(false);
    }
    if (snapOnEntity!=NULL) {
        snapOnEntity->setChecked(false);
    }
    if (snapCenter!=NULL) {
        snapCenter->setChecked(false);
    }
    if (snapMiddle!=NULL) {
        snapMiddle->setChecked(false);
    }
    if (snapDist!=NULL) {
        snapDist->setChecked(false);
    }
    if (snapIntersection!=NULL) {
        snapIntersection->setChecked(false);
    }
    if (snapIntersectionManual!=NULL) {
        snapIntersectionManual->setChecked(false);
    }

    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->disableSnaps();
    }
}

void WF_ActionHandler::slotRestrictNothing() {
    disableRestrictions();
    if (restrictNothing!=NULL) {
        restrictNothing->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapRestriction(LX_Define::RestrictNothing);
    }
    setCurrentAction(LX_Define::ActionRestrictNothing);
}

void WF_ActionHandler::slotRestrictOrthogonal() {
    disableRestrictions();
    if (restrictOrthogonal!=NULL) {
        restrictOrthogonal->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapRestriction(LX_Define::RestrictOrthogonal);
    }
    setCurrentAction(LX_Define::ActionRestrictOrthogonal);
}

void WF_ActionHandler::slotRestrictHorizontal() {
    disableRestrictions();
    if (restrictHorizontal!=NULL) {
        restrictHorizontal->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapRestriction(LX_Define::RestrictHorizontal);
    }
    setCurrentAction(LX_Define::ActionRestrictHorizontal);
}

void WF_ActionHandler::slotRestrictVertical() {
    disableRestrictions();
    if (restrictVertical!=NULL) {
        restrictVertical->setChecked(true);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setSnapRestriction(LX_Define::RestrictVertical);
    }
    setCurrentAction(LX_Define::ActionRestrictVertical);
}

void WF_ActionHandler::disableRestrictions() {
    if (restrictNothing!=NULL) {
        restrictNothing->setChecked(false);
    }
    if (restrictOrthogonal!=NULL) {
        restrictOrthogonal->setChecked(false);
    }
    if (restrictHorizontal!=NULL) {
        restrictHorizontal->setChecked(false);
    }
    if (restrictVertical!=NULL) {
        restrictVertical->setChecked(false);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->disableRestrictions();
    }
}


/**
 * Updates the snap mode for the current document from the selected menu.
 * Used after the active window changed.
 */
void WF_ActionHandler::updateSnapMode() {
    if (snapFree!=NULL && snapFree->isChecked()) {
        slotSnapFree();
    } else if (snapGrid!=NULL && snapGrid->isChecked()) {
        slotSnapGrid();
    } else if (snapEndpoint!=NULL && snapEndpoint->isChecked()) {
        slotSnapEndpoint();
    } else if (snapOnEntity!=NULL && snapOnEntity->isChecked()) {
        slotSnapOnEntity();
    } else if (snapCenter!=NULL && snapCenter->isChecked()) {
        slotSnapCenter();
    } else if (snapMiddle!=NULL && snapMiddle->isChecked()) {
        slotSnapMiddle();
    } else if (snapDist!=NULL && snapDist->isChecked()) {
        slotSnapDist();
    } else if (snapIntersection!=NULL && snapIntersection->isChecked()) {
        slotSnapIntersection();
    }

    // snap restricitons:
    if (restrictNothing!=NULL && restrictNothing->isChecked()) {
        slotRestrictNothing();
    } else if (restrictOrthogonal!=NULL && restrictOrthogonal->isChecked()) {
        slotRestrictOrthogonal();
    } else if (restrictHorizontal!=NULL && restrictHorizontal->isChecked()) {
        slotRestrictHorizontal();
    } else if (restrictVertical!=NULL && restrictVertical->isChecked()) {
        slotRestrictVertical();
    }

    // lock of relative zero:
    if (lockRelativeZero!=NULL) {
        slotLockRelativeZero(lockRelativeZero->isChecked());
    }
}

void WF_ActionHandler::slotSetRelativeZero() {
    setCurrentAction(LX_Define::ActionSetRelativeZero);
}

void WF_ActionHandler::slotLockRelativeZero(bool on) {
    if (lockRelativeZero!=NULL) {
        lockRelativeZero->setChecked(on);
    }
    if (on) {
        setCurrentAction(LX_Define::ActionLockRelativeZero);
    } else {
        setCurrentAction(LX_Define::ActionUnlockRelativeZero);
    }
    if (cadToolBarSnap!=NULL) {
        cadToolBarSnap->setLockRelativeZero(on);
    }
}

void WF_ActionHandler::slotInfoInside() {
    setCurrentAction(LX_Define::ActionInfoInside);
}

void WF_ActionHandler::slotInfoDist() {
    setCurrentAction(LX_Define::ActionInfoDist);
}

void WF_ActionHandler::slotInfoDist2() {
    setCurrentAction(LX_Define::ActionInfoDist2);
}

void WF_ActionHandler::slotInfoAngle() {
    setCurrentAction(LX_Define::ActionInfoAngle);
}

void WF_ActionHandler::slotInfoTotalLength() {
    setCurrentAction(LX_Define::ActionInfoTotalLength);
}

void WF_ActionHandler::slotInfoArea() {
    setCurrentAction(LX_Define::ActionInfoArea);
}

void WF_ActionHandler::slotLayersDefreezeAll() {
    setCurrentAction(LX_Define::ActionLayersDefreezeAll);
}

void WF_ActionHandler::slotLayersFreezeAll() {
    setCurrentAction(LX_Define::ActionLayersFreezeAll);
}

void WF_ActionHandler::slotLayersAdd() {
    setCurrentAction(LX_Define::ActionLayersAdd);
}

void WF_ActionHandler::slotLayersRemove() {
    setCurrentAction(LX_Define::ActionLayersRemove);
}

void WF_ActionHandler::slotLayersEdit() {
    setCurrentAction(LX_Define::ActionLayersEdit);
}

void WF_ActionHandler::slotLayersToggleView() {
    setCurrentAction(LX_Define::ActionLayersToggleView);
}

void WF_ActionHandler::slotLayersToggleLock() {
    setCurrentAction(LX_Define::ActionLayersToggleLock);
}


void WF_ActionHandler::slotBlocksDefreezeAll() {
    setCurrentAction(LX_Define::ActionBlocksDefreezeAll);
}

void WF_ActionHandler::slotBlocksFreezeAll() {
    setCurrentAction(LX_Define::ActionBlocksFreezeAll);
}

void WF_ActionHandler::slotBlocksAdd() {
    setCurrentAction(LX_Define::ActionBlocksAdd);
}

void WF_ActionHandler::slotBlocksRemove() {
    setCurrentAction(LX_Define::ActionBlocksRemove);
}

void WF_ActionHandler::slotBlocksAttributes() {
    setCurrentAction(LX_Define::ActionBlocksAttributes);
}

void WF_ActionHandler::slotBlocksEdit() {
    setCurrentAction(LX_Define::ActionBlocksEdit);
}

void WF_ActionHandler::slotBlocksInsert() {
    setCurrentAction(LX_Define::ActionBlocksInsert);
}

void WF_ActionHandler::slotBlocksToggleView() {
    setCurrentAction(LX_Define::ActionBlocksToggleView);
}

void WF_ActionHandler::slotBlocksCreate() {
    setCurrentAction(LX_Define::ActionBlocksCreate);
}

void WF_ActionHandler::slotBlocksExplode() {
    setCurrentAction(LX_Define::ActionBlocksExplode);
}


void WF_ActionHandler::slotOptionsDrawing() {
    setCurrentAction(LX_Define::ActionOptionsDrawing);
}

void WF_ActionHandler::slotFocusNormal() {
    //WF_GraphicView* gv = mainWindow->getGraphicView();
    //if (gv!=NULL) {
        //gv->setFocus();
        mainWindow->setFocus2();
    //}
}

/**
    * Creates link to snap tool bar so we can update the button
    * state if the snapping action changes.
    */
void WF_ActionHandler::setCadToolBarSnap(UI_CadToolBarSnap* tb) {
    cadToolBarSnap = tb;
}

// EOF
